Export Your Plotly Plot as a HTML Widget

#install.packages("htmlwidgets)
library(htmlwidgets)
## Warning: package 'htmlwidgets' was built under R version 4.4.3
#install.packages("plotly")
library(plotly)
## Warning: package 'plotly' was built under R version 4.4.3
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 4.4.3
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(ggplot2)

Create Plot and Convert to Plotly Plot

example_df = data.frame(
  "state" = c("CT","RI","NY","MA","PA","ME"),
  "value" = c(1,2,3,4,5,6))

example_plot = ggplot(data = example_df, aes(x = state, y = value, color = state), ) +
  geom_point()
example_plot

example_plotly = plotly::ggplotly(example_plot, tooltip = c("y", "x"))
example_plotly

Save Plotly as HTML to Working Directory

setwd("C:/Users/asare/Downloads")
saveWidget(as_widget(example_plotly), "example_plotly.html", selfcontained = TRUE)

Embed Plotly HTML in Substack

  1. Upload the HTML file into the PopHIVE Github Substack Repository folder that is relevant to your blog post
  2. Insert Github Pages link to your Plotly HTML website into your blog post. YOU MUST USE THE FOLLOWING LINK https://pophive.github.io/Substack/INSERT THE PATH TO YOUR PLOTLY HTML FILE.html